<?php

namespace App\Models\TempFile;

use App\Http\Traits\FileUploadTrait;
use Illuminate\Database\Eloquent\Model;

class TempFile extends Model
{
    use FileUploadTrait;

    protected $fillable = [
        'path',
    ];

    public static function getFileById(int $id) {
        $tempFile = TempFile::find($id);
        if (!empty($tempFile)) {
            $tempFilePath = TempFile::find($id)->path;
            $file = TempFile::getFile($tempFilePath);
            return $file;
        }
        return null;
    }

    public static function deleteFileAndModel(int $id) {
        $tempFile = TempFile::find($id);
        TempFile::deleteFile($tempFile->path);
        return $tempFile->delete();
    }
}
